namespace QMVnSoft.Lists
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormDmKsLister : FormListLister
    {
        private IContainer components;

        public FormDmKsLister()
        {
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            base.SuspendLayout();
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.ClientSize = new Size(0x34f, 0x10a);
            base.LocalFieldCount = 0;
            base.LocalFieldName = "Stt";
            base.LocalTableName = "DMKS";
            base.Name = "FormDmKsLister";
            base.OrderFieldNames = "Stt0";
            base.ShowDoneButton = true;
            base.ShowFreeFields = false;
            base.ShowMergeButton = false;
            this.Text = "B\x00fat toán khóa sổ";
            base.UserLastKey = Keys.Tab;
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        public override bool OnAdd()
        {
            base.LocalFormEditor = new FormDmKsEditor();
            return base.OnAdd();
        }

        public override void OnDone()
        {
            if ((base.LocalGridBrowser.SelectedRows.Count == 0) && (base.LocalTable.Rows.Count == 0))
            {
                return;
            }
            FormDmKsFilter filter = new FormDmKsFilter();
            filter.Ngay_Ct2 = AppInstance.EndWorkingDate;
            filter.ShowDialog();
            if (!filter.CheckAccepted)
            {
                return;
            }
            if ((((DateTime) filter.Ngay_Ct2) < AppInstance.OpeningDateOfSubEnterprice) || (((DateTime) filter.Ngay_Ct2) <= AppInstance.EndingDateOfSubEnterprice))
            {
                MessageBox.Show("Đã khóa dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            DmKsDataAccess access = new DmKsDataAccess();
            if (base.LocalGridBrowser.SelectedRows.Count != 0)
            {
                string str = null;
                DataRow row = null;
                DataRow row2 = null;
                foreach (DataGridViewRow row3 in base.LocalGridBrowser.SelectedRows)
                {
                    if ((row == null) || (row["Stt0"].ToString().CompareTo(((DataRowView) row3.DataBoundItem).Row["Stt0"].ToString()) == 1))
                    {
                        row = ((DataRowView) row3.DataBoundItem).Row;
                    }
                }
                access.Ket_Chuyen(AppInstance.Subsidiary, filter.Ngay_Ct2, row["Stt"], AppInstance.UserName);
                while (true)
                {
                    str = null;
                    foreach (DataGridViewRow row4 in base.LocalGridBrowser.SelectedRows)
                    {
                        if (((str == null) || (str.CompareTo(((DataRowView) row4.DataBoundItem).Row["Stt0"].ToString()) == 1)) && (((DataRowView) row4.DataBoundItem).Row["Stt0"].ToString().CompareTo(row["Stt0"].ToString()) == 1))
                        {
                            str = ((DataRowView) row4.DataBoundItem).Row["Stt0"].ToString();
                            row2 = ((DataRowView) row4.DataBoundItem).Row;
                        }
                    }
                    if ((str == null) || (str.CompareTo(row["Stt0"].ToString()) != 1))
                    {
                        goto Label_02CA;
                    }
                    row = row2;
                    access.Ket_Chuyen(AppInstance.Subsidiary, filter.Ngay_Ct2, row["Stt"], AppInstance.UserName);
                }
            }
            object obj2 = ((DataRowView) base.LocalGridBrowser.CurrentRow.DataBoundItem).Row["Stt"];
            access.Ket_Chuyen(AppInstance.Subsidiary, filter.Ngay_Ct2, obj2, AppInstance.UserName);
        Label_02CA:
            base.OnDone();
        }

        public override bool OnEdit()
        {
            base.LocalFormEditor = new FormDmKsEditor();
            return base.OnEdit();
        }

        public override void OnFillData()
        {
            object[][] objArray = new object[6][];
            object[] objArray2 = new object[4];
            objArray2[0] = "Stt0";
            objArray2[1] = "Số thứ tự";
            objArray2[2] = "C";
            objArray[0] = objArray2;
            object[] objArray3 = new object[4];
            objArray3[0] = "Tk_Di";
            objArray3[1] = "Tài khoản đi";
            objArray3[2] = "C";
            objArray[1] = objArray3;
            object[] objArray4 = new object[4];
            objArray4[0] = "Ten_Tk_Di";
            objArray4[1] = "Tên tài khoản đi";
            objArray4[2] = "C";
            objArray[2] = objArray4;
            object[] objArray5 = new object[4];
            objArray5[0] = "Tk_Den";
            objArray5[1] = "Tài khoản đến";
            objArray5[2] = "C";
            objArray[3] = objArray5;
            object[] objArray6 = new object[4];
            objArray6[0] = "Ten_Tk_Den";
            objArray6[1] = "Tên tài khoản đến";
            objArray6[2] = "C";
            objArray[4] = objArray6;
            object[] objArray7 = new object[4];
            objArray7[0] = "Dien_Giai";
            objArray7[1] = "Diễn giải";
            objArray7[2] = "C";
            objArray[5] = objArray7;
            base.ColNames = objArray;
            base.OnFillData();
        }

        public override void OnRefresh()
        {
            base.LocalDataSet = new DmKsDataAccess().GetDataSet();
            base.OnRefresh();
        }
    }
}

